package com.itheima.stock.controller;

import com.itheima.stock.annotation.Limiter;
import com.itheima.stock.api.UserControllerAPI;
import com.itheima.stock.dto.LoginDTO;
import com.itheima.stock.response.ResponseResult;
import com.itheima.stock.service.UserService;
import com.itheima.stock.vo.CaptchaVO;
import com.itheima.stock.vo.LoginVO;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 28188
 */
@RestController
public class UserController implements UserControllerAPI {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }


    /**
     * 获取验证码接口
     *
     * @return 返回包含验证码信息的响应结果
     */
    @Limiter
    @Override
    public ResponseResult<CaptchaVO> generateCaptcha() {
        return ResponseResult.ok(userService.generateCaptcha());
    }

    /**
     * 登录接口
     *
     * @param loginDTO 登录参数
     * @return 登录结果
     */
    @Override
    public ResponseResult<LoginVO> login(@RequestBody LoginDTO loginDTO) {
        return ResponseResult.ok(userService.login(loginDTO));
    }
}